package com.starbaba.loanAccountInput.view;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;

import com.base.common.database.BaseDao;
import com.base.common.database.DaoHelper;
import com.base.common.exception.AppException;
import com.base.common.log.LogService;
import com.google.gson.JsonObject;
import com.opensymphony.xwork2.ActionSupport;
import com.starbaba.common.ResultJson;
import com.starbaba.controllog.model.ControlLogCategory;
import com.starbaba.core.hibernate.Page;
import com.starbaba.core.utils.PropertyParamMapBuilder;
import com.starbaba.core.utils.Struts2Utils;
import com.starbaba.core.utils.json.JsonUtils;
import com.starbaba.core.web.page.PageResponse;
import com.starbaba.core.web.struts2.BaseAction;
import com.starbaba.core.web.struts2.JsonResult;
import com.starbaba.loanAccountInput.model.CommProductChannel;
import com.starbaba.loanAccountInput.model.CommUserModel;
import com.starbaba.loanAccountInput.model.LoanAccountInputModel;
import com.starbaba.loanAccountInput.model.LoanProductInfoModel;
import com.starbaba.loanAccountInput.model.PartnerName;
import com.starbaba.loanAccountInput.model.PlatformModel;
import com.starbaba.loanAccountInput.model.PrdChanelNameModel;
import com.starbaba.loanAccountInput.model.SpreadChannelManagerModel;
import com.starbaba.loanActivity.model.ContentActivityModel;
import com.starbaba.model.db.Cps_Repeat_Config;
import com.starbaba.model.dictionary.Constant;
import com.starbaba.model.dictionary.IOrderStatus;
import com.starbaba.model.dictionary.IOrderType;
import com.starbaba.model.exception.AppToastException;
import com.starbaba.model.utils.NumberUtil;
import com.starbaba.tools.sequence.Sequence;
import com.starbaba.util.ExcelOperateUtil;
import com.tuanzi.server.loan_base.util.PhoneNumNideUtil;

public class LoanAccountInputAction extends BaseAction {

	
	private ArrayList<ControlLogCategory> logCategorysArrayList;

	private String savePath;

	private String uploadFileName;

	private File upload;

	private String uploadContentType;
	
	final BaseDao dao = new BaseDao(Constant.POOL_LIFE);

	private InputStream inputStream;

	private String fileName;
	
	public String show() {
		
		paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
		parsePageRequest();
		PageResponse pageResponse = new PageResponse();
		int flag = 0;//判断是否有上传文件
		try {
			List<CommProductChannel> channelList = getChannelList();
			List<LoanProductInfoModel> partnerList = getPartnerList();
			List<SpreadChannelManagerModel> productList = getProductList();
			ServletActionContext.getRequest().getSession().setAttribute("channelList", channelList);
			ServletActionContext.getRequest().getSession().setAttribute("partnerList", partnerList);
			ServletActionContext.getRequest().getSession().setAttribute("productList", productList);
		
			paramsMap.put("flag", flag);
			JsonObject result = new JsonObject();
			ResultJson resultJs = new ResultJson();
			resultJs.msg = "修改成功";
			result.add("result", resultJs.toJSON());
			sendJsonMessage(result.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public void getDataList() {
		List<LoanAccountInputModel> listTemp = (List<LoanAccountInputModel>)ServletActionContext.getRequest().getSession().getAttribute("loanInputList");
		if (listTemp == null) {
			getDBList();//查询数据库信息
		} else {
			getTempList();//查询导入数据
		}
		
	}
	
	//显示数据库数据
	public void getDBList() {
		paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
		String cPhone = (String) paramsMap.get("cPhone");
		String startTime = (String) paramsMap.get("startTime");
		String endTime = (String) paramsMap.get("endTime");
		String handleStartTime = (String) paramsMap.get("handleStartTime");
		String handleEndTime = (String) paramsMap.get("handleEndTime");
		String product_id = (String) paramsMap.get("product_id");
		String channel = (String) paramsMap.get("channel");
		String partner_id = (String) paramsMap.get("partnerId");
		String platform = (String) paramsMap.get("platform");
		try {
			parsePageRequest();

			page = new Page();
			page.setPageNo(pageRequest.getIDisplayStart() / pageRequest.getIDisplayLength() + 1);
			page.setPageSize(pageRequest.getIDisplayLength());

			StringBuffer sqlBuilder = new StringBuffer();
			StringBuffer countBuilder = new StringBuffer();
			sqlBuilder.append("select prd_id as prdId,channel_id as channelId,partner_id as partnerId,mobnum,loan_money as loanMoney,settlement_money as settlementMoney,operator,platform_id as platform,");
			sqlBuilder.append("DATE_FORMAT(apply_time, '%Y-%m-%d %H:%i:%s') AS applyTime,");
			sqlBuilder.append("DATE_FORMAT(loan_time, '%Y-%m-%d %H:%i:%s') AS loanTime,");
			sqlBuilder.append("DATE_FORMAT(ctime, '%Y-%m-%d %H:%i:%s') AS ctime,");
			sqlBuilder.append("DATE_FORMAT(confirm_time, '%Y-%m-%d %H:%i:%s') AS confirmTime");
			sqlBuilder.append(" from loan_input where 1=1");
			countBuilder
					.append("select count(1) from loan_input where 1=1");
			
			if (StringUtils.isNotEmpty(platform)) {
				sqlBuilder.append(" and platform_id = " + platform);
				countBuilder.append(" and platform_id = " + platform);
			}
			if (StringUtils.isNotEmpty(product_id)) {
				sqlBuilder.append(" and prd_id = " + product_id);
				countBuilder.append(" and prd_id = " + product_id);
			}
			if (StringUtils.isNotEmpty(channel)) {
				sqlBuilder.append(" and channel_id = " + channel);
				countBuilder.append(" and channel_id = " + channel);
			}
			if (StringUtils.isNotEmpty(partner_id)) {
				sqlBuilder.append(" and partner_id = " + partner_id);
				countBuilder.append(" and partner_id = " + partner_id);
			}
			if (StringUtils.isNotEmpty(endTime)) {
				sqlBuilder.append(" and apply_time <= '" + endTime + "'");
				countBuilder.append(" and apply_time <= '" + endTime + "'");
			}
			if (StringUtils.isNotEmpty(startTime)) {
				sqlBuilder.append(" and apply_time >= '" + startTime +"'");
				countBuilder.append(" and apply_time >= '" + startTime +"'");
			}
			if (StringUtils.isNotEmpty(handleEndTime)) {
				sqlBuilder.append(" and loan_time <= '"+ handleEndTime +"'");
				countBuilder.append(" and loan_time <= '"+ handleEndTime +"'");
			}
			if (StringUtils.isNotEmpty(handleStartTime)) {
				sqlBuilder.append(" and loan_time >= '"+ handleStartTime +"'");
				countBuilder.append(" and loan_time >= '"+ handleStartTime +"'");
			}
			if (StringUtils.isNotEmpty(cPhone)) {
				sqlBuilder.append(" and mobnum like '%"+ cPhone +"%'");
				countBuilder.append(" and mobnum like '%"+ cPhone +"%'");
			}
			
			sqlBuilder.append(" order by ctime desc limit " + pageRequest.getIDisplayStart() + " , " + pageRequest.getIDisplayLength());
			
			
			List<LoanAccountInputModel> list = dao.list(sqlBuilder.toString() ,LoanAccountInputModel.class);
			
			//关联产品名、渠道名
			String pcSql = "SELECT b.prd_name as prdName,c.channel_name as channelName"
					   + " FROM loan.comm_user AS a LEFT JOIN loan.spread_channel_manager AS b ON a.product_id = b.prd_id"
					   + " LEFT JOIN loan.comm_product_channel AS c ON a.channel = c.channel_code"
					   + " WHERE"
					   + " a.mobnum = ?";
			
			//关联合作方名
			String pSql = "select name as partnerName from loan.loan_product_info where id = ?";
			SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			if (list != null) {
				for (LoanAccountInputModel laim : list) {
					
					//平台
					if (laim.getPlatform() != null) {
						if (laim.getPlatform() == 0) {
							laim.setPlatformName("通用");
						} else if(laim.getPlatform() == 1) {
							laim.setPlatformName("android");
						} else {
							laim.setPlatformName("ios");
						}
					}
					if (StringUtils.isNotEmpty(laim.getMobnum())) {
						PrdChanelNameModel pcName = dao.get(pcSql, PrdChanelNameModel.class, laim.getMobnum());
						if(pcName != null){
							
							laim.setPrdName(pcName.getPrdName());
							laim.setChannelName(pcName.getChannelName());
						}
					}
					if (laim.getPartnerId() != null) {
						PartnerName pName = dao.get(pSql, PartnerName.class, laim.getPartnerId());
						if (pName != null) {
							laim.setPartnerName(pName.getPartnerName());
						}
					}
					
					laim.setMobnum(PhoneNumNideUtil.hideNum(laim.getMobnum()));
					laim.setPartnerName(PhoneNumNideUtil.hideName(laim.getPartnerName()));
				}
			}
				
			
			page.setDatas(list);
			int num = 0;
			try {
				num = dao.getInt(countBuilder.toString());
			} catch (AppException e) {
				e.printStackTrace();
			}
			page.setTotalCount(num);
			returnData();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	//显示内存数据
	public void getTempList() {
		paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
		parsePageRequest();
		page = new Page();
		List<LoanAccountInputModel> listTemp = (List<LoanAccountInputModel>)ServletActionContext.getRequest().getSession().getAttribute("loanInputList");
		page.setDatas(listTemp);
		
		try {
			//page.setTotalCount(listTemp.size());
			returnData();
		} catch (Exception e) {
			e.printStackTrace();
		}
	} 
	
	public String uploadAllFinanceReport() throws IOException {
		
		BaseDao dao = new BaseDao(Constant.POOL_LIFE);
		paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
		File file = upload;
		
		if (file.exists()) {
			String fileName = file.getAbsolutePath();
			fileName = fileName.replace(".tmp", ".xls");
			file.renameTo(new File(fileName));
			file = new File(fileName);	
		}
		
		//判断是导入文件有错1，还是数据格式有错2，
		int errorFlag = 1;
		
		StringBuffer errorStr = new StringBuffer();	
		try {
			//处理excel文件
			ExcelOperateUtil poi = new ExcelOperateUtil();
			
			String[][] result = poi.getData(file);
			int flag = 1;
			int rowIndex = 2;
			int[] rowErrorFlag = new int[result.length+1];
			for (String[] record : result) {
				if(flag == 1){
					flag++;
					continue;
				}
				String partnerId = record[0];
				String cPhone = record[1];
				String applyTime = record[2];
				String loanTime = record[3];
				String loanMoney = record[4];
				String settlementMoney = record[5];

				if (StringUtils.isEmpty(cPhone)) {
					errorStr.append("line " + rowIndex + ": " + "手机号码不能为空   \\n ");
					rowErrorFlag[rowIndex] = 1;
				}
				if (cPhone.length() > 11) {
					cPhone = cPhone.substring(0,11);
				}
				if (StringUtils.isNotEmpty(cPhone)) {
					cPhone = NumberUtil.handleNumeric(cPhone);
				}
				if (!NumberUtil.isNumeric(cPhone) || cPhone.length() != 11) {
					errorStr.append("line " + rowIndex + ": " + "手机号码格式错误    \\n");
					rowErrorFlag[rowIndex] = 1;
				}
				if(partnerId.length() > 0){
					partnerId = partnerId.substring(0,partnerId.indexOf("."));
				}
				if (StringUtils.isEmpty(partnerId)) {				
					errorStr.append("line " + rowIndex + ": " + "合作方ID为空    \\n");
					rowErrorFlag[rowIndex] = 1;
				}
				if (StringUtils.isNotEmpty(partnerId) && !NumberUtil.isNumeric(partnerId)) {
					errorStr.append("line " + rowIndex + ": " + "合作方ID不是数字    \\n");
					rowErrorFlag[rowIndex] = 1;
				}
				if (StringUtils.isEmpty(loanMoney)) {
					loanMoney = "0";
				}	
				if (StringUtils.isEmpty(settlementMoney)) {
					loanMoney = "0";
				}
			
				//申请时间不能大于贷款时间
				if (StringUtils.isNotEmpty(applyTime) && StringUtils.isNotEmpty(loanTime)) {
					if (compareDate(applyTime, loanTime) != -1) {	
						errorStr.append("line " + rowIndex + ": " + "申请时间不能大于贷款时间  \\n");
						rowErrorFlag[rowIndex] = 1;
					}
				}
				if (rowErrorFlag[rowIndex] == 1) {
					errorFlag = 2;
				}
				rowIndex++;
			}
			
			List<LoanAccountInputModel> loanInputList = new ArrayList<LoanAccountInputModel>();
			flag = 1;
			int index = 0;
			rowIndex = 2;
			for (String[] record : result) {
				if(flag == 1){
					flag++;
					continue;
				}
				if (rowErrorFlag[rowIndex++] == 1) {
					continue;
				}
				
				String partnerId = record[0].substring(0,record[0].indexOf("."));
				String cPhone = record[1].substring(0,record[1].indexOf("."));
				String applyTime = record[2];
				String loanTime = record[3];
				String loanMoney = record[4];
				String settlementMoney = record[5];

				cPhone = NumberUtil.handleNumeric(cPhone);

				//贷款金额
				if (StringUtils.isEmpty(loanMoney)) {
					loanMoney = "";
				}
				//结算金额
				if (StringUtils.isEmpty(settlementMoney)) {
					settlementMoney = "";
				}

				//处理数据
				String sql = "SELECT a.mobnum,a.channel as channelId,a.product_id as prdId,a.phoneid,b.prd_name as prdName,c.channel_name as channelName"
						   + " FROM loan.comm_user AS a LEFT JOIN loan.spread_channel_manager AS b ON a.product_id = b.prd_id"
						   + " LEFT JOIN loan.comm_product_channel AS c ON a.channel = c.channel_code"
						   + " WHERE"
						   + " a.mobnum = ?";
			    
				LoanAccountInputModel inputModel = dao.get(sql, LoanAccountInputModel.class, cPhone);
				
				if (inputModel == null) {
					inputModel = new LoanAccountInputModel();
				}
				
				//合作方ID关联合作方名
				String partnerSql = "select id,name from loan.loan_product_info where id = ?";
				LoanProductInfoModel partnerModel = dao.get(partnerSql, LoanProductInfoModel.class, Integer.parseInt(partnerId));
				if (partnerModel != null) {
					if (partnerModel.getId() != null) {
						inputModel.setPartnerId(partnerModel.getId());
					}
					if (StringUtils.isNotEmpty(partnerModel.getName()))
						inputModel.setPartnerName(partnerModel.getName());
				}
				SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				if (StringUtils.isNotEmpty(applyTime)) {
					Date date = format.parse(applyTime);
					inputModel.setApplyTime(format.format(date));
				}
				if (StringUtils.isNotEmpty(loanTime)) {
					Date date = format.parse(loanTime);
					inputModel.setLoanTime(format.format(date));
				} 
				if (StringUtils.isNotEmpty(loanMoney)) {
					inputModel.setLoanMoney(loanMoney);
				}
				if (StringUtils.isNotEmpty(settlementMoney)) {
					inputModel.setSettlementMoney(settlementMoney);
				}
				if (StringUtils.isNotEmpty(cPhone)) {
					inputModel.setMobnum(cPhone);
				}
				if (StringUtils.isNotEmpty(partnerId)) {
					inputModel.setPartnerId(Integer.parseInt(partnerId));
				}
				//创建时间
				SimpleDateFormat tempFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	            String cdate = tempFormat.format(new Date());
	            inputModel.setCtime(cdate);

				//标记是否关联了平台
				boolean platformFlag = false;
				
				//关联平台,一个手机号可能对应多个平台
				if (StringUtils.isNotEmpty(inputModel.getPhoneid())) {
					BaseDao platformDao = new BaseDao("stat");
					
					String platformSql = "select phone_id as phoneId, platform from stat_app_new where phone_id = ?";
					
					List<PlatformModel> platformModelList = platformDao.list(platformSql, PlatformModel.class, inputModel.getPhoneid());
					
					if (platformModelList != null) {
						
						for (PlatformModel p : platformModelList) {
							
							if(StringUtils.isNotEmpty(p.getPlatform())) {
								
								if ("android".equals(p.getPlatform().trim())) {
									inputModel.setPlatform(1);//安卓
								}
								else if ("ios".equals(p.getPlatform().trim())) {
									inputModel.setPlatform(2);//ios
								} else {
									inputModel.setPlatform(0);//通用
								}
								inputModel.setPlatformName(p.getPlatform());//平台名
								inputModel.setPhoneid(null);
								//装进集合
								inputModel.setPosition(index++);
								loanInputList.add(inputModel);
								platformFlag = true;
							}
							
						}
						
					}
					
				}
				
				//无关联平台
				if (platformFlag == false) {
					inputModel.setPosition(index++);
					loanInputList.add(inputModel);
				}
				
	            
			}
	
			paramsMap.put("loanInputList", loanInputList);
			ServletActionContext.getRequest().getSession().setAttribute("loanInputList", loanInputList);
			if (errorFlag == 2) {
				paramsMap.put("message","部分数据导入成功，错误数据如下：  \\n" + errorStr.toString());
			}
			else {
				paramsMap.put("message", "导入成功!");
			}
			paramsMap.put("flag", 1);//已经上传文件
			
		} catch (Exception e) {			
			paramsMap.put("message", e.getMessage());
			
			LogService.error(e);
		}
		return ActionSupport.SUCCESS;
	}

	
	
	public List<CommProductChannel> getChannelList() {
		
		//渠道ID关联渠道名
		String channelSql = "select channel_code,channel_name from loan.comm_product_channel";
		try {
			List<CommProductChannel> channelList  = dao.list(channelSql, CommProductChannel.class, new Object[]{});
			return channelList;
		} catch (AppException e) {
			
			e.printStackTrace();
		}
		return null;

	}
	
	public List<LoanProductInfoModel> getPartnerList() {
		//合作方ID关联合作方名
		String partnerSql = "select id,name from loan_product_info";
		try {
			List<LoanProductInfoModel> partnerList = dao.list(partnerSql, LoanProductInfoModel.class, new Object[]{});
			return partnerList;
		} catch (AppException e) {
			
			e.printStackTrace();
		}
		return null;
				
				
	}
	
	public List<SpreadChannelManagerModel> getProductList() {
		
		//产品ID关联产品名		
		String channelSql = "select prd_id,prd_name from loan.spread_channel_manager";
		try {
			List<SpreadChannelManagerModel> prdList = dao.list(channelSql, SpreadChannelManagerModel.class, new Object[]{});
			return prdList;
		} catch (AppException e) {
			
			e.printStackTrace();
		}
		return null;
	}
	
	//清除文件缓存
	public void cleanFileBuf() throws Exception {
		try {
			paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
			List<LoanAccountInputModel> loanInputList = (List<LoanAccountInputModel>) ServletActionContext.getRequest().getSession().getAttribute("loanInputList");
			
			
			if(loanInputList == null){
				sendJsonMessage(new JsonResult("0"));
				return;
			}
			ServletActionContext.getRequest().getSession().removeAttribute("loanInputList");
			paramsMap.put("flag", 0);//文件已上传，此时无上传文件
			sendJsonMessage(new JsonResult("1"));
		} catch (Exception e) {
			e.printStackTrace();
			sendErrorMessage(e);
		}
	}
	
	public void handleRecord() throws Exception {
	
		
		try {
			paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
			
			String operator = (String) paramsMap.get("operator");
			String[] ids =  (String[]) paramsMap.get("ids[]");
		
			
			List<LoanAccountInputModel> loanInputList = (List<LoanAccountInputModel>) ServletActionContext.getRequest().getSession().getAttribute("loanInputList");
			if (loanInputList == null) {
				paramsMap.put("flag", 0);//文件已上传，此时无上传文件
				sendJsonMessage(new JsonResult("1"));
				return;
			}
	
			for (String key : ids) {
				if(!NumberUtil.isNumeric(NumberUtil.handleNumeric(key))){
					continue;
				}
				if (Integer.parseInt(key) < loanInputList.size()) {
					SimpleDateFormat tempFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		            String confirmTime = tempFormat.format(new Date());
					LoanAccountInputModel temp = loanInputList.get(Integer.parseInt(key));
					temp.setPlatformName(null);
					temp.setPhoneid(null);
					temp.setPartnerName(null);
					temp.setPrdName(null);
					temp.setChannelName(null);
					
					temp.setConfirmTime(confirmTime);
					temp.setCtime(confirmTime);
					temp.setOperator(operator);
					
					StringBuffer insertSql = new StringBuffer();
					//insertSql.append("insert into loan_input(prd_id,channel_id,partner_id,platform_id,mobnum,apply_time,loan_time,loan_money,settlement_money,operator,confirm_time,ctime,position)");
					//insertSql.append("values(?,?,?,?,?,?,?,?,?,?,?,?,?)");
					insertSql.append("insert into loan_input(");
					int valueNum = 0;
					if (temp.getPrdId() != null) {
						insertSql.append("prd_id,");
						valueNum++;
					}
					if (temp.getChannelId() != null) {
						insertSql.append("channel_id,");
						valueNum++;
					}
					if (temp.getPartnerId() != null) {
						insertSql.append("partner_id,");
						valueNum++;
					}
					if (temp.getPlatform() != null) {
						insertSql.append("platform_id,");
						valueNum++;
					}
					if (StringUtils.isNotEmpty(temp.getMobnum())) {
						insertSql.append("mobnum,");
						valueNum++;
					}
					if (StringUtils.isNotEmpty(temp.getApplyTime())) {
						insertSql.append("apply_time,");
						valueNum++;
					}
					if (StringUtils.isNotEmpty(temp.getLoanTime())) {
						insertSql.append("loan_time,");
						valueNum++;
					}
					if (StringUtils.isNotEmpty(temp.getLoanMoney())) {
						insertSql.append("loan_money,");
						valueNum++;
					}
					if (StringUtils.isNotEmpty(temp.getSettlementMoney())) {
						insertSql.append("settlement_money,");
						valueNum++;
					}
					if (StringUtils.isNotEmpty(temp.getOperator())) {
						insertSql.append("operator,");
						valueNum++;
					}
					if (StringUtils.isNotEmpty(temp.getConfirmTime())) {
						insertSql.append("confirm_time,");
						valueNum++;
					}
					if (StringUtils.isNotEmpty(temp.getCtime())) {
						insertSql.append("ctime,");
						valueNum++;
					}
					insertSql.append("position) value(");
					for(int i = 0; i < valueNum; i++){
						insertSql.append("?,");
					}
					insertSql.append("?)");
					
					
					dao.add(insertSql.toString(), new Object[]{
													temp.getPrdId()!=null?temp.getPrdId():null,
													temp.getChannelId()!=null?temp.getChannelId():null,
													temp.getPartnerId()!=null?temp.getPartnerId():null,
													temp.getPlatform()!=null?temp.getPlatform():null,
													StringUtils.isNotEmpty(temp.getMobnum())?temp.getMobnum():null,
													StringUtils.isNotEmpty(temp.getApplyTime())?temp.getApplyTime():null,
													StringUtils.isNotEmpty(temp.getLoanTime())?temp.getLoanTime():null,
													StringUtils.isNotEmpty(temp.getLoanMoney())?temp.getLoanMoney():null,
													StringUtils.isNotEmpty(temp.getSettlementMoney())?temp.getSettlementMoney():null,
													StringUtils.isNotEmpty(temp.getOperator())?temp.getOperator():null,
													StringUtils.isNotEmpty(temp.getConfirmTime())?temp.getConfirmTime():null,
													StringUtils.isNotEmpty(temp.getCtime())?temp.getCtime():null,
													temp.getPosition()
													
					});
					
				}
			}
			
			ServletActionContext.getRequest().getSession().removeAttribute("loanInputList");
			paramsMap.put("flag", 0);//文件已上传，此时无上传文件
			paramsMap.put("message", "录入数据库成功");
			sendJsonMessage(new JsonResult("1"));
		} catch (Exception e) {
			e.printStackTrace();
			paramsMap.put("message", "录入数据库失败");
			sendErrorMessage(e);
		}
	}
	
	public static int compareDate(String date1,String date2) throws ParseException {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(format.parse(date1));
		Date d1 = calendar.getTime();
		calendar.setTime(format.parse(date2));
		Date d2 = calendar.getTime();
		return d1.compareTo(d2); // d1 < d2  返回 -1 , d1 > d2 返回 1 , d1 = d2 返回 0
	}

	@Override
	public ArrayList<ControlLogCategory> getProduct() {
		return logCategorysArrayList;
	}

	public String getSavePath() {
		return savePath;
	}

	public void setSavePath(String savePath) {
		this.savePath = savePath;
	}

	public File getUpload() {
		return upload;
	}

	public void setUpload(File upload) {
		this.upload = upload;
	}

	public String getUploadFileName() {
		return uploadFileName;
	}

	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public String getUploadContentType() {
		return uploadContentType;
	}

	public void setUploadContentType(String uploadContentType) {
		this.uploadContentType = uploadContentType;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public InputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}
	
}
